package com.pcj.blog.web;/**
 * @param
 * @author pcj
 * @date 2022/1/7 10:55
 * @return
 */

import com.pcj.blog.po.Tag;
import com.pcj.blog.service.BlogService;
import com.pcj.blog.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;


/**
 *
 * @className TagShowController
 * @author pengcj
 * @date 2022/1/7 10:55
 */
@Controller
public class TagShowController {
    @Autowired
    private TagService tagService;
    @Autowired
    private BlogService blogService;
    @GetMapping("/tags/{id}")
    public String Tag(@PageableDefault(size = 1,sort = "updateTime",direction = Sort.Direction.DESC) Pageable pageable,
                      Model model, @PathVariable Long id){
        List<Tag>tags=tagService.listTag();
        if(id==-1){
            id=tags.get(0).getId();
        }
        model.addAttribute("tags",tags);
        model.addAttribute("page",blogService.ListBlog(id,pageable));
        model.addAttribute("activeTagid",id);
        return "tags";
    }
}
